home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!dirkv
- From: dirkv@netcom.com (Dirk Vermeersch)
- Subject: Re: What is wrong with this code?
- Message-ID: <dirkvDoHs79.MJr@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- X-Newsreader: TIN [version 1.2 PL1]
- References: <4il0pn$fp@news1.io.org>
- Date: Tue, 19 Mar 1996 01:59:32 GMT
- Sender: dirkv@netcom.netcom.com
-
- Ivan (ticica@io.org) wrote:
-
- : Please, can someone tell me what's wrong with this program? It's driving
- : me nuts. When I compile it with Borland C++ 3.1 I get null pointer
- : assignment. With Watcom C++ 9.5 the last line (cout << a * 3) prints some
- : junk. Thanks in advance.
- :
- : Ivan
- : -------------------------------------------------------------------------
-
-
- Hi Ivan,
-
- The problem is in the operator * function :
- a new vector is created on the stack and than returned. This would
- be OK if the vector had a copy constructor (vector(const &vector)), but
- here the default copy constructor is used. The default copy constructor
- just copies the members ( shallow copy ==> 'data' and 'name' point to the
- same memory as for the retvec on the stack ).
- Upon returning from the function the vector's destructor is called. This
- will delete the name and the data members, but these pointers are still
- being used in the object returned by the function.
-
- Dirk
-
-
- :
-
-